<?php
$section = 'business_solution';
$titre = _LB_BUSINESS_MANAGEMENT;
$smarty->assign("titre", $titre);

//get object ID
$id = Request::getIntNumber('id');
$act = Request::getIntNumber('act');

//get back link
$backlink = Session::getBackLink($section,"list/?");

$bs = new Business_Solution();
if($id)
{
	if(!$bs->get($id))
		redirect($backlink);
}
$bss = array();
Business_Solution::getTree($bss);

//if action = UPDATE or CREATE
if ($act == ACT_VALID_EDIT)
{
	$bs->TITLE = trim(Request::get('TITLE'));
    $bs->SHORT_DESC = trim($_POST['SHORT_DESC']);
    $bs->DESCRIPTION = trim($_POST['DESCRIPTION']);
    $bs->DISABLED = Request::getNumber('DISABLED');
    $bs->ID_PARENT = Request::getNumber('ID_PARENT');
    $bs->POS = Request::getNumber('POS');
	if ($bs->validateInput())
	{
		$bs->save();

		redirect($backlink);
	}

}

include_once CKEDITOR_BASE_DIR. "ckeditor.php";
$CKEditor = new CKEditor();
$CKEditor->basePath = CKEDITOR_BASE_PATH;
$CKEditor->config['height'] = 600;
$CKEditor->config['filebrowserBrowseUrl'] = CKFINDER_BASE_PATH.'ckfinder.html';
$CKEditor->config['filebrowserImageBrowseUrl'] = CKFINDER_BASE_PATH.'ckfinder.html?type=Images';
$CKEditor->config['filebrowserFlashBrowseUrl'] = CKFINDER_BASE_PATH.'ckfinder.html?type=Flash';
$CKEditor->config['filebrowserUploadUrl'] = CKFINDER_BASE_PATH.'core/connector/php/connector.php?command=QuickUpload&type=Files';
$CKEditor->config['filebrowserImageUploadUrl'] = CKFINDER_BASE_PATH.'core/connector/php/connector.php?command=QuickUpload&type=Images';
$CKEditor->config['filebrowserFlashUploadUrl'] = CKFINDER_BASE_PATH.'core/connector/php/connector.php?command=QuickUpload&type=Flash';
//create cfer
$cfer = new Cfer(array(
	_LB_ACCUEIL => Utils::getHomeLink(),
	_LB_STATIC_PAGE_MANAGEMENT => $backlink,
	($id == 0? _LB_ADD_BUSINESS : _LB_EDIT_BUSINESS) => Utils::getCurrentLink() ));

//if validate is false, display form again
$smarty->assign('cfer', $cfer);
$smarty->assign('bs', $bs);
$smarty->assign('bss', $bss);
$smarty->assign('backlink', $backlink);
$smarty->assign('CKEditor', $CKEditor);
$smarty->display('business_solution_form.html');